#ifndef __RTP__PACKET__
#define  __RTP__PACKET__
#ifdef __Win32__
#pragma warning(disable:4786)
#endif

#include "OSHeaders.h"
#include "OSMacro.h"

typedef enum{
	RTP_PACKET	= 1,
	RDT_PACKET	= 2,
	END_PACKET	= 3
} DATA_TYPE;


enum FRAME_TYPE {FT_UNKOWN = 0, FT_KEYFRAME = 1, FT_VIDEO_P = 2, FT_VIDEO_B = 3, FT_VIDEO_OTHER, FT_AUDIO, FT_OTHERS};

class RtpPacket
{
public:
	enum KMediaType
	{
		MEDIA_VIDEO = 1,
		MEDIA_AUDIO = 2
	};
	enum 
	{
		STORE=1,	//store data
		LINK=2	//only save point
	};

	RtpPacket(UInt8 vMode=STORE);
	~RtpPacket();

	void Reset();
		
public:
	Bool	SetRtpHeader(UInt16 v_RtpFlags);
	Bool	SetRtpSeqNumber(UInt16 v_RtpSeqNumber);
	Bool	SetTimeStamp(UInt32 v_TimeStamp);
	Bool	SetSSRC(UInt32 v_SSRC);
	Bool	SetFrameType(FRAME_TYPE v_Type);
	Bool	SetTrackID(UInt32 v_TrackID);
//	Bool	SetTime(Float32 v_Time);
	Bool	SetMediaType(UInt8 nType) { m_MediaType = nType; return TRUE;}
	const UInt16	GetSeqNumber();
	const UInt32	GetTimeStamp();
	const UInt32	GetSSRC();
	const UInt32	GetTrackID();
	const FRAME_TYPE	GetFrameType();
//	const Float32	GetTime();
	const UInt8	GetMediaType() { return m_MediaType; }

	//save point
	void	Link(UInt32 inTrackID,char *pData, UInt16 v_DataLen, UInt64 vTimeStamp,DATA_TYPE dt = RTP_PACKET);
	//copy data
	void	Assign(UInt32 inTrackID,char *pData,UInt16 v_DataLen, UInt64 vTimeStamp,DATA_TYPE dt = RTP_PACKET);
	
	void	SetTimeStampExt(UInt64 vTimeStamp);
	UInt64	GetTimeStampExt();//Unit: ms
	Bool	IsMark();

public:
	Char*	GetCurDataBuf();
	Bool	MoveCurPos(UInt16 v_DataLen);
	Char*	GetRtpData(UInt16& v_Len);
	UInt32	GetRtpLength();
	void	SetDataType(DATA_TYPE nType) {m_nDataType = nType;};
	DATA_TYPE	GetDataType() {return m_nDataType;};
	void	CreatePacket(char* pData,UInt32 v_DataLen); //	????RTPPacket??

private:
	DATA_TYPE	m_nDataType;
	UInt8	m_MediaType;
	UInt8	m_Mode;
	UInt16	m_curPos;
	UInt32	m_TrackID;
	UInt16	m_RtpHeader;
	UInt16	m_SeqNumber;
	UInt32	m_TimeStamp;		//Unit: Timescale
	UInt32	m_SSRC;
//	Float32	m_Time;
	FRAME_TYPE	m_FrameType;
	//Char	m_Data[RFS_RTP_PACKETSIZE];
	char *	m_pData;

	Bool	m_IsMark;
	UInt64	m_TimeStampExt;	//ms
};

struct RtpGreater
{
	Bool operator() (RtpPacket* v_Packet1,RtpPacket* v_Packet2);
};

#endif

